namespace DotNetNuke.Services.Search
{
    using DotNetNuke.Entities.Portals;
    using System;
    using System.Collections;

    /// -----------------------------------------------------------------------------
    /// Namespace:  DotNetNuke.Services.Search
    /// Project:    DotNetNuke
    /// Class:      SearchEngine
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The SearchEngine  manages the Indexing of the Portal content
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// [cnurse]	11/15/2004	documented
    /// </history>
    /// -----------------------------------------------------------------------------
    public class SearchEngine
    {
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetContent gets all the content and passes it to the Indexer
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="Indexer">The Index Provider that will index the content of the portal</param>
        /// <history>
        /// [cnurse]	11/15/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        protected SearchItemInfoCollection GetContent(IndexingProvider Indexer)
        {
            SearchItemInfoCollection SearchItems = new SearchItemInfoCollection();
            ArrayList arrPortals = new PortalController().GetPortals();
            int refIntHelperL0 = arrPortals.Count - 1;
            for (int intPortal = 0; intPortal <= refIntHelperL0; intPortal++)
            {
                PortalInfo objPortal = (PortalInfo) arrPortals[intPortal];
                SearchItems.AddRange(Indexer.GetSearchIndexItems(objPortal.PortalID));
            }
            return SearchItems;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetContent gets the Portal's content and passes it to the Indexer
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="PortalID">The Id of the Portal</param>
        /// <param name="Indexer">The Index Provider that will index the content of the portal</param>
        /// <history>
        /// [cnurse]	11/15/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        protected SearchItemInfoCollection GetContent(int PortalID, IndexingProvider Indexer)
        {
            SearchItemInfoCollection SearchItems = new SearchItemInfoCollection();
            SearchItems.AddRange(Indexer.GetSearchIndexItems(PortalID));
            return SearchItems;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// IndexContent indexes all Portal content
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// [cnurse]	11/15/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public void IndexContent()
        {
            IndexingProvider Indexer = IndexingProvider.Instance();
            SearchDataStoreProvider.Instance().StoreSearchItems(this.GetContent(Indexer));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// IndexContent indexes the Portal's content
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="PortalID">The Id of the Portal</param>
        /// <history>
        /// [cnurse]	11/15/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public void IndexContent(int PortalID)
        {
            IndexingProvider Indexer = IndexingProvider.Instance();
            SearchDataStoreProvider.Instance().StoreSearchItems(this.GetContent(PortalID, Indexer));
        }
    }
}

